#include<string>
#include<iostream>

using namespace std;

class Solution {
public:
    int lengthOfLastWord(string s) {
        auto it = s.rbegin();
        int num = 0;
        while (it != s.rend())
        {
            if (*it !=' ')
            {
                break;
            }
            it++;
        }
        while (it != s.rend())
        {
            if (*it != ' ')
            {
                num = num + 1;
                it++;
            }
            else
            {
                break;
            }
        }
        return num;
    }
};

int main()
{
    Solution s;
    cout<<s.lengthOfLastWord("hwlllahaiudh dawiudhaioud    ");
    return 0;
}